home *** CD-ROM | disk | FTP | other *** search
- (*********************************************************************
- * *** Pascal ステップカウントツール *** *
- * *
- * HAPPyのサンプルプログラム *
- * (作者 浅野比富美 Public Domain Software) *
- *********************************************************************)
-
- program StepCounter(source,output) ;
-
- var source : text ; { Pascalソースファイル }
- ch : char ; { 読み込み文字 }
- lnum : integer ; { 行数 }
- snum : integer ; { ステップ数 }
- step : Boolean ; { ステップカウント対象行時 真 }
-
- (*********************************)
- (* シフトJISコード1バイト目チェック汎用関数 *) { 81h~9Fh E0h~FCh だと真 }
- (*********************************)
- function iskanji(ch : char) : Boolean ;
- var intch : integer ;
- begin
- intch := ord(ch) ;
- iskanji := (intch-129 in [0..30]) or (intch-224 in [0..28])
- end ; { intch in [129..159,224..252] の表記は HAPPyでは不可(^^); }
-
-
- (******************************)
- (* 1文字読み込み *)
- (******************************)
- procedure nextch ;
- begin
- if eoln(source) then { 改行コードの時 }
- begin
- readln(source) ; { 改行コード読み飛ばし }
- lnum := lnum + 1 ; { 行番号カウントアップ }
- if step then snum := snum + 1 ; { 有効行の時 ステップ数カウント }
- step := false ;
- ch := ' ' { 空白に置き換え }
- end
- else read(source,ch) { 改行でなければそのまま読む }
- end ;
-
- (******************************)
- (* 注釈読み飛ばし *)
- (******************************)
- procedure skipComment ;
- var endflag : Boolean ; { 注釈の終わりの時 真 }
- begin
- repeat
- nextch ;
- while iskanji(ch) do { シフトJISコードの1バイト目ならば }
- begin
- nextch ; nextch { 2バイト分読み飛ばし }
- end ;
- if ch = '*' then
- begin
- endflag := (source^ = ')') or (source^ = '}') ;
- { source^ には次の文字が入っているのがミソ }
- if endflag then nextch
- end
- else endflag := ch = '}'
- until endflag ;
- nextch
- end ;
-
- (****************************)
- (* メイン処理 *)
- (****************************)
- begin
- reset(source) ;
- lnum := 0 ;
- snum := 0 ;
- step := false ;
- nextch ;
-
- repeat
- if (ch = ' ') or (ch = chr(9)) then nextch { 空白 水平タブは無視する }
- else if ch = '''' then { 文字列の時 }
- repeat { '自身を指定する時 '' とすること }
- repeat nextch until ch = '''' ; { になっているので そこを考慮する }
- nextch
- until ch <> ''''
- else if ch = '{' then skipComment { コメント読み飛ばし }
- else if ch = '(' then { ( * 形式のコメントかチェック }
- begin
- nextch ;
- if ch = '*' then skipComment
- else step := true { コメント始まり以外の ( は有効 }
- end
- else { プログラムとして有効な記号 }
- begin
- step := true ;
- nextch
- end
- until eof(source) ; { 本当は 「end.」までだけど妥協 }
-
- writeln('行数 : ',lnum:5) ;
- writeln('ステップ数 : ',snum:5) ;
- writeln('コメント率 : ',(lnum-snum)/lnum*100:5:1,'%')
- end.